define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/acdevice/index',
                    add_url: 'jdy/acdevice/add',
                    edit_url: 'jdy/acdevice/edit',
                    del_url: 'jdy/acdevice/del',
                    multi_url: 'jdy/acdevice/multi',
                    table: 'jdy_acdevice',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        //{field: 'anchang_id', title: __('Anchang_id')},
                        //{field: 'stype_id', title: __('Stype_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'anchang.name', title: __('Anchang.name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'smallcategory.name', title: __('類型'), operate:false},
                        {field: 'smallcategory_id', title: __('類型'), visible: false, addClass: "selectpage", extend: "data-source='jdy/smallcategory/index' data-field='name'"},
                        {field: 'status', title: __('Status'), searchList: {"啟用":__('啟用'),"停用":__('停用')}, formatter: Table.api.formatter.status},
                        {field: 'bgdate', title: __('Bgdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'anchang.id', title: __('Anchang.id')},
                        //{field: 'anchang.building_id', title: __('Anchang.building_id')},
                        //{field: 'anchang.room_id', title: __('Anchang.room_id')},
                        //{field: 'anchang.name', title: __('Anchang.name')},
                        //{field: 'anchang.addr', title: __('Anchang.addr')},
                        //{field: 'anchang.remark', title: __('Anchang.remark')},
                        //{field: 'anchang.contact1_id', title: __('Anchang.contact1_id')},
                        //{field: 'anchang.contact2_id', title: __('Anchang.contact2_id')},
                        //{field: 'anchang.companywindow_id', title: __('Anchang.companywindow_id')},
                        //{field: 'anchang.xianshi', title: __('Anchang.xianshi')},
                        //{field: 'anchang.xzq', title: __('Anchang.xzq')},
                        //{field: 'anchang.mapurl', title: __('Anchang.mapurl'), formatter: Table.api.formatter.url},
                        //{field: 'anchang.orderdate', title: __('Anchang.orderdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'anchang.create_time', title: __('Anchang.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'anchang.update_time', title: __('Anchang.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'smallcategory.id', title: __('Smallcategory.id')},
                        //{field: 'smallcategory.bigcategory_id', title: __('Smallcategory.bigcategory_id')},
                        //{field: 'smallcategory.type', title: __('Smallcategory.type')},
                        //{field: 'smallcategory.name', title: __('Smallcategory.name')},
                        //{field: 'smallcategory.alias', title: __('Smallcategory.alias')},
                        //{field: 'smallcategory.ignore_duration_time', title: __('Smallcategory.ignore_duration_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'smallcategory.status', title: __('Smallcategory.status')},
                        //{field: 'smallcategory.opman', title: __('Smallcategory.opman')},
                        //{field: 'smallcategory.create_time', title: __('Smallcategory.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'smallcategory.update_time', title: __('Smallcategory.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                    ]
                ]
            });

            $(".datetimerange").attr({'autocomplete': 'off'});

            $(document).on("click", ".drsb", function () {
                var url = 'jdy/acdevice/drsb';
                var _this = $(this);
                Fast.api.ajax({
                    url: url,
                }, function (data, ret) {

                    $(".btn-refresh").trigger("click");
                });
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});